package com.jdb.loan.controller.assembler;

import com.jdb.loan.api.dto.LoanCategoryDTO;
import com.jdb.loan.provider.entity.LoanCategoryDO;
import org.springframework.cglib.beans.BeanCopier;

import java.util.Objects;

public class LoanCategoryAssmbler {


    private static final BeanCopier fromCopier = BeanCopier.create(
            LoanCategoryDTO.class, LoanCategoryDO.class, false);
    private static final BeanCopier toCopier = BeanCopier.create(
            LoanCategoryDO.class, LoanCategoryDTO.class, false);


    public static LoanCategoryDO fromDTO(LoanCategoryDTO loanCategoryDTO) {
        if (Objects.isNull(loanCategoryDTO)) {
            return null;
        }
        LoanCategoryDO loanCategoryDO = new LoanCategoryDO();
        fromCopier.copy(loanCategoryDTO, loanCategoryDO, null);
        return loanCategoryDO;
    }

    public static LoanCategoryDTO toDTO(LoanCategoryDO loanCategoryDO) {
        if (Objects.isNull(loanCategoryDO)) {
            return null;
        }
        LoanCategoryDTO loanCategoryDTO = new LoanCategoryDTO();
        toCopier.copy(loanCategoryDO, loanCategoryDTO, null);
        loanCategoryDTO.setType("category");
        return loanCategoryDTO;
    }
}
